package com.linkage.event.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.linkage.common.exception.ServiceException;
import com.linkage.event.pojo.dao.FlagRemarkMapper;
import com.linkage.event.pojo.entity.FlagRemark;
import com.linkage.event.service.FlagRemarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FlagRemarkServiceImpl implements FlagRemarkService {

    @Autowired
    private FlagRemarkMapper flagRemarkMapper;

    @Override
    public List<FlagRemark> queryList(FlagRemark record) {
        return flagRemarkMapper.queryFlagList(record);
    }

    @Override
    public void addFlagRemark(FlagRemark remark) {
        if (StrUtil.hasEmpty(remark.getFlagDesc(),remark.getFlagName())){
            throw new ServiceException(500,"标识描述或者标识名称为空");
        }
        remark.setId(IdUtil.fastSimpleUUID());
        remark.setCreateTime(System.currentTimeMillis());
        flagRemarkMapper.insertSelective(remark);
    }

    @Override
    public void modifyFlagRemark(FlagRemark remark) {
        if(StrUtil.isEmpty(remark.getId())){
            throw new ServiceException(500,"标识id参数为空");
        }
        flagRemarkMapper.updateByPrimaryKeySelective(remark);
    }

    @Override
    public void deleteFlagRemark(String id) {
        if(StrUtil.isEmpty(id)){
            throw new ServiceException(500,"标识id参数为空");
        }
        flagRemarkMapper.deleteByPrimaryKey(id);
    }

    @Override
    public FlagRemark queryInfo(String id){
        return flagRemarkMapper.selectByPrimaryKey(id);
    }
}
